package com.visizen.wisdomclass.server.client;

import com.visizen.wisdomclass.server.model.WcPublicscoreLevel;
import com.visizen.wisdomclass.server.model.WcPublicscoreLevelExample;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface WcPublicscoreLevelMapper {
    /**
     * 获取用户的积分等级信息
     *
     * @param userId
     * @return
     */
    @Select(" select * from (\n" +
            " SELECT\n" +
            "  l.*,u.score\n" +
            " FROM wc_publicscore_level AS l INNER JOIN wc_user_public_role AS u\n" +
            "    ON u.user_id = #{userId} AND l.role_id = u.role_id order by target_score desc\n" +
            ") as data\n" +
            " where data.score > target_score limit 1;")
    WcPublicscoreLevel selectByUserId(@Param("userId") Long userId);

    @Select("select * from wc_publicscore_level where role_id=#{roleId}")
    List<WcPublicscoreLevel> selectByRole(@Param("roleId") Long roleId);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table wc_publicscore_level
     *
     * @mbggenerated
     */
    @SelectProvider(type = WcPublicscoreLevelSqlProvider.class, method = "countByExample")
    int countByExample(WcPublicscoreLevelExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table wc_publicscore_level
     *
     * @mbggenerated
     */
    @DeleteProvider(type = WcPublicscoreLevelSqlProvider.class, method = "deleteByExample")
    int deleteByExample(WcPublicscoreLevelExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table wc_publicscore_level
     *
     * @mbggenerated
     */
    @Delete({
            "delete from wc_publicscore_level",
            "where leve_id = #{leve_id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long leve_id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table wc_publicscore_level
     *
     * @mbggenerated
     */
    @Insert({
            "insert into wc_publicscore_level (leve_id, attach_id, ",
            "role_id, target_score, ",
            "level_name)",
            "values (#{leve_id,jdbcType=BIGINT}, #{attach_id,jdbcType=BIGINT}, ",
            "#{role_id,jdbcType=BIGINT}, #{target_score,jdbcType=INTEGER}, ",
            "#{level_name,jdbcType=VARCHAR})"
    })
    int insert(WcPublicscoreLevel record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table wc_publicscore_level
     *
     * @mbggenerated
     */
    @InsertProvider(type = WcPublicscoreLevelSqlProvider.class, method = "insertSelective")
    int insertSelective(WcPublicscoreLevel record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table wc_publicscore_level
     *
     * @mbggenerated
     */
    @SelectProvider(type = WcPublicscoreLevelSqlProvider.class, method = "selectByExample")
    @Results({
            @Result(column = "leve_id", property = "leve_id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "attach_id", property = "attach_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "role_id", property = "role_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "target_score", property = "target_score", jdbcType = JdbcType.INTEGER),
            @Result(column = "level_name", property = "level_name", jdbcType = JdbcType.VARCHAR)
    })
    List<WcPublicscoreLevel> selectByExample(WcPublicscoreLevelExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table wc_publicscore_level
     *
     * @mbggenerated
     */
    @Select({
            "select",
            "leve_id, attach_id, role_id, target_score, level_name",
            "from wc_publicscore_level",
            "where leve_id = #{leve_id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "leve_id", property = "leve_id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "attach_id", property = "attach_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "role_id", property = "role_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "target_score", property = "target_score", jdbcType = JdbcType.INTEGER),
            @Result(column = "level_name", property = "level_name", jdbcType = JdbcType.VARCHAR)
    })
    WcPublicscoreLevel selectByPrimaryKey(Long leve_id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table wc_publicscore_level
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcPublicscoreLevelSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") WcPublicscoreLevel record, @Param("example") WcPublicscoreLevelExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table wc_publicscore_level
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcPublicscoreLevelSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") WcPublicscoreLevel record, @Param("example") WcPublicscoreLevelExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table wc_publicscore_level
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcPublicscoreLevelSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(WcPublicscoreLevel record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table wc_publicscore_level
     *
     * @mbggenerated
     */
    @Update({
            "update wc_publicscore_level",
            "set attach_id = #{attach_id,jdbcType=BIGINT},",
            "role_id = #{role_id,jdbcType=BIGINT},",
            "target_score = #{target_score,jdbcType=INTEGER},",
            "level_name = #{level_name,jdbcType=VARCHAR}",
            "where leve_id = #{leve_id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(WcPublicscoreLevel record);
}